#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define mes(x) memset(x,0,sizeof(x))
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

template <typename T>
void write(T x){
	bool sgn = 0;
	if(x < 0) x = -x,sgn = 1;
	T stk[20],cnt = 0;
	while(x){
		stk[++cnt] = x%10;
		x/=10;
	}
	if(sgn) putchar('-');
	for(int i = cnt;i >= 1;i--) putchar(stk[i]+48);
	if(cnt == 0) putchar('0');
	putchar('\n');
}

const int MAXN = 1010;

typedef struct {int v,w,nxt;}edge;

int a[MAXN],h[MAXN*MAXN*2],dis[MAXN*MAXN*2],cnt,n,m,s,t;
edge e[MAXN*MAXN*6];
bool vis[MAXN*MAXN*2];
void link(int x,int y,int w){
	e[++cnt] = edge{y,w,h[x]};h[x] = cnt;
	e[++cnt] = edge{x,w,h[y]};h[y] = cnt;
}

int id(int x,int y,int p){return (x-1)*m+y+p*n*m;}

void dijk(){
	memset(dis,0x3f,sizeof(dis));
	dis[s] = 0;priority_queue<pii>q;
	q.push(pii(0,s));
	while(q.size()){
		int x = q.top().se;q.pop();
		if(vis[x]) continue;
		vis[x] = 1;
		if(x == t) return;
		for(int i = h[x];i;i = e[i].nxt){
			int y = e[i].v;
			if(dis[y] > dis[x] + e[i].w){
				dis[y] = dis[x] + e[i].w;
				q.push(pii(-dis[y],y));
			}
		}
	}
}

int main (){
	n = in,m = in; s = 0,t = n*m*2 + 1;
	for(int i = 1;i <= n;i++)
		for(int j = 1;j < m;j++){
			int x = in;
			if(i == 1) link(id(i,j,0),t,x);
			else if(i == n) link(s,id(i-1,j,1),x);
			else link(id(i-1,j,1),id(i,j,0),x);
		}
	for(int i = 1;i < n;i++)
		for(int j = 1;j <= m;j++){
			int x = in;
			if(j == 1) link(s,id(i,j,1),x);
			else if(j == m) link(id(i,j-1,0),t,x);
			else link(id(i,j-1,0),id(i,j,1),x);
		}
	for(int i = 1;i < n;i++)
		for(int j = 1;j < m;j++){
			int x = in;
			link(id(i,j,0),id(i,j,1),x);
		}
	dijk();
	printf("%d\n",dis[t]);
	return 0;
}
